﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

namespace XqWebSite
{
    public partial class WebForm18 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)//判断是否回发
            {
                GetDate();//调用函数
            }
        }

        private void GetDate()
        {
            DataSet ds = DBHelper.GetDataSet("select * from Toushu");
            this.GridView1.DataSource = ds.Tables[0];//获取数据并绑定到控件 
            this.GridView1.DataBind();
        }
        

        protected void But_ss_Click(object sender, EventArgs e)
        {
            string SQL = "select * from Toushu where 1=1";

            if (!string.IsNullOrEmpty(TextBox1.Text))
            {
                SQL = SQL + " and ID ='" + TextBox1.Text + "'";
            }
            DataSet ds = DBHelper.GetDataSet(SQL);
            this.GridView1.DataSource = ds.Tables[0];//获取数据并绑定到控件 
            this.GridView1.DataBind(); 

        }

        protected void But_sc_Click(object sender, EventArgs e)
        {

            string ID = TextBox2.Text;//获取要删除的主键
            string SQL = "delete Toushu where ID='" + ID + "'";
            bool bRet = DBHelper.ExecSql(SQL);//执行删除操作
            if (bRet)
            {
                DBHelper.ShowMessage(Page, "操作成功！", "ZhTousuguanli.aspx");
            }
            else
            {
                DBHelper.ShowMessage(Page, "操作失败！", "ZhTousuguanli.aspx");
            }
            GetDate();
        }

        protected void Btu_xg_Click(object sender, EventArgs e)
        {
            Response.Redirect("ZhTousuguanliXg.aspx");
        }
    }
}